//
//  MYGMyCollectViewController.swift
//  MYDoctor
//
//  Created by Denny on 2024/3/18.
//

import UIKit
import JXSegmentedView
class MYGMyCollectViewController: MYGBaseController {
   var type = 2
   lazy var segment:JXSegmentedView = {
        let control  = JXSegmentedView()
        control.delegate = self
        return control
    }()
    
    var segmentedDataSource: JXSegmentedTitleDataSource = {
        let control = JXSegmentedTitleDataSource()
        control.titles = ["会议", "新闻", "话题","文献"]
        control.isTitleColorGradientEnabled = true
        return control
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "我的收藏"
        configSegMent()
    }
    
    func configSegMent() {
        self.view.addSubview(segment)
        segment.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(46.5)
        }
        //关联dataSource
        segment.dataSource = self.segmentedDataSource
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorWidth = 20
        segment.indicators = [indicator]
        
        
        let listContainerView = JXSegmentedListContainerView(dataSource: self)
        view.addSubview(listContainerView)
        listContainerView.snp.makeConstraints { make in
            make.top.equalTo(segment.snp.bottom).offset(15)
            make.left.right.bottom.equalToSuperview()
        }
        //关联listContainer
        segment.listContainer = listContainerView
    }
}
extension MYGMyCollectViewController: JXSegmentedViewDelegate {
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
}


extension MYGMyCollectViewController : JXSegmentedListContainerViewDataSource {
    //返回列表的数量
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return segmentedDataSource.titles.count
    }
    
    //返回遵从`JXSegmentedListContainerViewListDelegate`协议的实例
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let vc =  MYGCollectListViewController()
        vc.type = exchangeType(index: index)
        return vc
    }
    
    func exchangeType(index:Int) ->Int {
        if index == 0 {
            self.type = 2//会议
        }
        if index == 1 {
            self.type = 6//新闻
        }
        if index == 2 {
            self.type = 1//话题
        }
        if index == 3 {
            self.type = 5//文献
        }
       
        return self.type
    }
}
